import sys
from PySide6.QtWidgets import QWidget, QVBoxLayout, QLabel, QApplication, QFormLayout, QHBoxLayout, QSpacerItem, QSpacerItem, QSizePolicy
import os
from PySide6.QtGui import QFont


class WebWidget(QWidget):

    def __init__(self, main_ui):
        super().__init__()
        self.main_ui = main_ui
        self.log_path = main_ui.log_path
        self.log_dir = main_ui.log_dir
        self.config = main_ui.config
        # self.tab_web_layout = QFormLayout(self)
        font = QFont()
        font.setPointSize(16)  # 设置字体大小为16点
        custom_row_widget = QWidget(self)
        custom_row_layout = QVBoxLayout(self)
        custom_row_widget.setLayout(custom_row_layout)
        address = self.config.options('web')
        for name in address:
            print(name)
            addr = self.config.get('web', name)
            web_lable = QLabel(self)
            web_lable.setFont(font)
            custom_row_layout.addWidget(web_lable)
            web_lable.setText(
                f'<a href="{addr}"> {name}:{addr}</a>')
            web_lable.setOpenExternalLinks(True)  # 设置QLabel打开外部链接
            web_lable.setToolTip('点击这里访问')

        self.setLayout(custom_row_layout)


# if __name__ == "__main__":
#     app = QApplication(sys.argv)
#     widget = WebWidget()
#     widget.resize(800, 600)
#     widget.show()
#     sys.exit(app.exec())
